package br.com.servlet.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import model.dao.DAOFactory;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import br.com.model.Game;

import com.google.gson.Gson;

@Controller
public class ServicoController 
{
	@RequestMapping("/gson-games")
	public void index( HttpServletResponse response )
	{
		Gson gb = new Gson( );
		
		List<Game> busca = DAOFactory.infGameDao( ).busca( "select g from Game g" );
		
		response.setContentType( "application/json" );
		
		String json = gb.toJson( busca );
		
		try 
		{
			PrintWriter writer = response.getWriter( );
			
			writer.println( json );
		} 
		catch( IOException e )
		{
			e.printStackTrace( );
		}
	}
}